import UIService from "../../services/uiService";
import { mgrs, sers } from "../../system/OverallSystem ";

const { ccclass, property } = cc._decorator;

/**
 * 默认为 背景 + 展示，缓动只作用于展示节点
 */
@ccclass
export default class PageBase extends cc.Component {

    public pageName: string = "页面基础组件";

    public id: number = -1;

    @property({ type: cc.Node, displayName: "需要展示的节点" })
    protected showNode: cc.Node = null;

    protected colseDoFun: Function = null;

    setCloseDoFun(colseDoFun: Function) {
        this.colseDoFun = colseDoFun;
    }


    start() {
        this._init();
    }

    protected _init() {
        this.open();
    }

    initData(data?){

    }

    open() {
        UIService.openPageBasicAni(this.showNode, true)
            .then(() => {

            }).catch(() => {

            });
    }

    close() {
        this.closeAni()
            .then(() => {
                this.colseDoFun && this.colseDoFun();

                sers().uiSrv.deletePageRecord(this.id);

                this.node.destroy();
                console.log("?????????????");
            })
            .catch();
    }

    onlyClose() {
        this.closeAni()
            .then(() => {
                sers().uiSrv.deletePageRecord(this.id);
                this.node.destroy();
            })
            .catch();
    }

    OnBtnClose() {
        mgrs().soundMgr.playBtnSound();
        this.close();
        console.log("OnBtnClose");
    }

    protected closeAni(isResume: boolean = false) {
        return UIService.closePageBasicAni(this.showNode, isResume);
    }

    update(dt) {

    }
}
